package com.ruoyi.web.controller.bl;


import com.ruoyi.bl.domain.BlAppParams;
import com.ruoyi.bl.service.IBlReportService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;


@RestController
@RequestMapping("/bl/report")
public class BlReportController extends BaseController
{
    @Autowired
    private IBlReportService blReportService;

    @Autowired
    private ISysUserService sysUserService;

    //查询商户当日总销售额
    //@ApiOperation(value = "查询商户当日总销售额",notes = "查询商户当日总销售额")
    @PreAuthorize("@ss.hasPermi('bl:orderMerchant:list')")
    @GetMapping("/findMerchanTotalTheDay")
    public AjaxResult findMerchanTotalTheDay(BlAppParams blAppParams)
    {
        blAppParams.setDeptId(getDeptId());
        LinkedHashMap list = blReportService.findMerchanTotalTheDay(blAppParams);
//        HashMap map  = new HashMap();
//        if(list == null ){
//            map.put("deptId",getDeptId());
//            map.put("totalAmount",0);
//            return success(map);
//        }
        return success(list);
    }

    //查询商户当日各商品销售额明细
    //@ApiOperation(value = "查询商户当日各商品销售额明细",notes = "查询商户当日各商品销售额明细")
    @PreAuthorize("@ss.hasPermi('bl:orderMerchant:list')")
    @GetMapping("/findMerchanTotalTheDayDetail")
    public AjaxResult findMerchanTotalTheDayDetail(BlAppParams blAppParams)
    {
        blAppParams.setDeptId(getDeptId());
        List<LinkedHashMap> list = blReportService.findMerchanTotalTheDayDetail(blAppParams);
        HashMap map  = new HashMap();
        if(list == null ){
            map.put("deptId",getDeptId());
            map.put("totalAmount",0);
            return success(map);
        }
        return success(list);
    }

    //查询供应商当日总销售额
    //@ApiOperation(value = "查询商户当日总销售额",notes = "查询商户当日总销售额")
    @PreAuthorize("@ss.hasPermi('bl:orderSupplier:list')")
    @GetMapping("/findSupplierTotalTheDay")
    public AjaxResult findSupplierTotalTheDay(BlAppParams blAppParams)
    {
        long userId = getUserId();
        SysUser sysUser = sysUserService.selectUserById(userId);
        if(sysUser.getSupplierId() == null){
            return error("请先在用户管理配置供应商");
        }
        blAppParams.setSupplierId(sysUser.getSupplierId());
        LinkedHashMap list = blReportService.findSupplierTotalTheDay(blAppParams);
//        HashMap map  = new HashMap();
////        if(list == null ){
////            map.put("supplierId",getDeptId());
////            map.put("totalAmount",0);
////            return success(map);
////        }
        return success(list);
    }

    //查询供应商当日各商品销售额明细
    //@ApiOperation(value = "查询商户当日各商品销售额明细",notes = "查询商户当日各商品销售额明细")
    @PreAuthorize("@ss.hasPermi('bl:orderSupplier:list')")
    @GetMapping("/finSupplierTotalTheDayDetail")
    public AjaxResult finSupplierTotalTheDayDetail(BlAppParams blAppParams)
    {
        long userId = getUserId();
        SysUser sysUser = sysUserService.selectUserById(userId);
        if(sysUser.getSupplierId() == null){
            return error("请先在用户管理配置供应商");
        }
        blAppParams.setSupplierId(sysUser.getSupplierId());
        List<LinkedHashMap> list = blReportService.finSupplierTotalTheDayDetail(blAppParams);
        HashMap map  = new HashMap();
        if(list == null ){
            map.put("supplierId",getDeptId());
            map.put("totalAmount",0);
            return success(map);
        }
        return success(list);
    }
}
